﻿$(document).ready(function () {

    $(".activateTask").click(function () {
        var $this = $(this),
            $taskActive = $this.closest(".info").find(".task-active"),
            sendData = { taskId: $this.closest(".monitoringTask").attr("data-id") },
            url;
        if ($this.attr("data-active").toLowerCase() == "true") {
            url = "/monitoring/StopMonitoring";
        } else {
            url = "/monitoring/StartMonitoring";
        }
        $.post(url, sendData, function (data) {
            if (data.result == "STOPPED") {
                $taskActive.text("NIE");
                $this.text("Start");
                $this.attr("data-active", "False");

            }
            else if (data.result == "ACTIVE") {
                $taskActive.text("TAK");
                $this.text("Stop");
                $this.attr("data-active", "True");
            }
        });
    });
    $(".removeTask").click(function() {
        var $task = $(this).closest(".monitoringTask"), sendData = { taskId: $task.attr("data-id") };
        $.post("/monitoring/RemoveTask", sendData, function (data) {
            if (data.result == "OK") {
                $task.remove();
            }
        });
    });
});